'''
given function f(), we want to run f() and print the amount of time it takes for the running of f()
'''

'''
def is_prime(n):
    factor, count = 1, 0
    while factor<=n:
        if n%factor == 0:
            count+=1
        factor+=1

    if count == 2:
        print('True')
    else:
        print('False. This number has ',count,' factors')
'''

import datetime
def run_time(f):
    def f_and_runtime(*args, **kw):
        start_time = datetime.datetime.now()
        result = f(*args, **kw)
        end_time = datetime.datetime.now()
        t = end_time-start_time
        print('run time of function '+f.__name__+' is: '+str(t))
        # file = open('./a.txt','w')
        # file.write('run time of function '+f.__name__+' is: '+str(t))
        # file.close()
        return result
    return f_and_runtime

#is_prime_and_runtime = run_time(is_prime)
#is_prime_and_runtime(10000000)

@run_time
def is_prime(n):
    factor, count = 1, 0
    while factor<=n:
        if n%factor == 0:
            count+=1
        factor+=1

    if count == 2:
        print('True')
    else:
        print('False.', n, ' has ',count,' factors')

is_prime(1000000)

@run_time
def sum_of_squares(n):
    s = 0
    for i in range(1,n+1):
        s += i**2
    print(s)

sum_of_squares(100)


